#ifndef CRC8_C_17f8fc13_16a3_402f_b152_212c94bd28eb
#define CRC8_C_17f8fc13_16a3_402f_b152_212c94bd28eb

/*
**
** Copyright (c) 2010 by Lorimark Solutions, LLC.
** All Rights Reserved.
** Send inquiries to: info@lorimarksolutions.com
**
*/

#include <crc8.h>

/////////////////////////////////////////////////////////////////////////
//
// FUNCTION:   uint8 Crc8C(uint8 seed,uint8 byte)
//
// PURPOSE:    Calculate the 8 bit CRC of a single byte.
//
// RETURN:     uint8 = new crc value.
//

uint8 crc8Result;
void crc8( uint8 dataByte )
{
   /*
   ** This is a flag used in the calculation of the CRC.
   **  we might benefit from converting this flag to a
   **  single bit rather than a whole byte but it's not
   **  yet known without doing some further testing.
   **
   */
   uint8 crcflg;

   /*
   ** Perform calculation on all 8 bits.
   **
   */
   uint8 bits = 8;

   /*
   ** loop through each bit individually
   **
   */
   while( bits-- )
   {
      /*
      ** We'll want to know if the bit we're examining
      **  is set or not.
      **
      */
      crcflg = (dataByte ^ crc8Result) & 1;

      /*
      ** Shift all the bits over.
      **
      */
      crc8Result     >>= 1;
      dataByte >>= 1;

      /*
      ** If the bit was set (earlier) then we need to
      **  apply the polynomial.
      **
      */
      if( crcflg != 0 )
         crc8Result ^= 0x8c;

   } // endwhile( bits-- )

} // endvoid crc8c( int8 byte )

#endif // #ifndef CRC8_C_17f8fc13_16a3_402f_b152_212c94bd28eb

